
import EventManager from "../../../Common/EventManager";
import { EventType } from "../../../GameSpecial/GameEventType";
import { sers } from "../../system/OverallSystem ";
import PageBase from "./pageBase";

const {ccclass, property} = cc._decorator;

@ccclass
export default class LoadingPage extends PageBase {

    public pageName: string = "加载中页面";

    // onLoad () {}
    @property(cc.Node)
    jiazaidian:Array<cc.Node>= []

    @property(cc.Node)
    quan1:cc.Node=null
    @property(cc.Node)
    quan2:cc.Node=null
    start () {
        // this.schedule(this.d,0.5)
        // for (const iterator of this.jiazaidian) {
        //     iterator.active = false
        // }
        cc.tween(this.quan1).call(()=>{
            // if(this.node){
            //     this.node.opacity = 0
            // }
        }).delay(1).call(()=>{
            if(this.node){
                this.node.opacity = 255
            }
        }).start()
        this.node.zIndex = 9999
        cc.log('show loading')
        
        // this.loadingTime = setTimeout(() => {
        //     EventManager.emit(EventType.DirectorEvent.loadingError)
        //     sers().uiSrv.hideLoding();
        // }, 10000);
    }

    private loadingTime = 0

    private index = 0
    d(){
        for (let i = 0; i < this.jiazaidian.length; i++) {
            const element = this.jiazaidian[i];
            if(this.index>=i){
                element.active = true
            }else{
                element.active = false
            }
           
        }
        this.index++
        if(this.index>=5){
            this.index = 0
        }
    }

    close(): void {
        // sers().uiSrv.deletePageRecord(this.id);
        this.unschedule(this.d)
        this.quan1.resumeAllActions()
        this.quan2.resumeAllActions()
        clearTimeout(this.loadingTime)
        this.node.destroy();
    }

    // update (dt) {}
}
